package exp1st;

public class ArrayList {

    String[] nums = new String[20];
    private int nZhaoQianChen;

    public ArrayList() {
        nZhaoQianChen = 0;
    }

    public void add(String n) {
        nums[nZhaoQianChen] = n;
        nZhaoQianChen++;
    }

    public int getnZhaoQianChen() {
        return nZhaoQianChen;
    }

    public void insert(int index, String n) {
        nZhaoQianChen ++;
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < index; i++) {
            arrayList.add(nums[i]);
        }
        arrayList.add(n);
        for (int i = index - 1; i < nZhaoQianChen; i++) {
            arrayList.add(nums[i + 1]);
        }

        nums = arrayList.nums;
    }

    public void delete(int index) {
        nZhaoQianChen --;
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < index; i++) {
            arrayList.add(nums[i]);
        }
        for (int i = index; i < nZhaoQianChen; i++) {
            arrayList.add(nums[i + 1]);
        }
        nums = arrayList.nums;
    }

    @Override
    public String toString() {
        String result = "[";
        for (int i = 0; i < nZhaoQianChen; i++) {
            result += nums[i] + ", ";
        }
        result = result.substring(0, result.length() - 2);
        result += "]";
        return result;
    }
}
